package lambdasinaction.chap5;

import lambdasinaction.chap4.Dish;

import java.util.Optional;

import static lambdasinaction.chap4.Dish.menu;

/**
 * Created by ThinkPad on 2017/8/19.
 */
public class Finding {
    public static void main(String... args) {
        if (isVegetarianFriendlyMenu()) {
            System.out.println("Vegetarian friendly");
        }
        System.out.println(isHealthyMenu());
        System.out.println(isHealthyMenu2());
        Optional<Dish> dish = findVegetarianDish();
        dish.ifPresent(dish1 -> System.out.println(dish1.getName()));
    }

    public static boolean isVegetarianFriendlyMenu() {
        return menu.stream().anyMatch(Dish::isVegetarian);
    }

    public static boolean isHealthyMenu() {
        return menu.stream().allMatch(dish -> dish.getCalories() < 1000);
    }

    public static boolean isHealthyMenu2() {
        return menu.stream().noneMatch(dish -> dish.getCalories() >= 1000);
    }

    public static Optional<Dish> findVegetarianDish() {
        return menu.stream().filter(Dish::isVegetarian).findAny();
    }
}
